/*
 * Date: 22/7/2008
 * Author: rcote
 * File: uk.ac.ebi.jmzml.model.mzml.FileDescription
 *
 * jmzml is Copyright 2008 The European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 *
 */

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-558
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2008.06.19 at 10:48:08 AM BST
//


package uk.ac.ebi.jmzml.model.mzml;

import uk.ac.ebi.jmzml.model.mzml.interfaces.MzMLObject;
import uk.ac.ebi.jmzml.model.mzml.params.ContactCVParam;
import uk.ac.ebi.jmzml.model.mzml.params.ContactUserParam;
import uk.ac.ebi.jmzml.model.mzml.params.FileDescriptionCVParam;
import uk.ac.ebi.jmzml.model.mzml.params.FileDescriptionUserParam;
import uk.ac.ebi.jmzml.model.mzml.utilities.ParamGroupUpdater;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * Information pertaining to the entire mzML file (i.e. not specific to any part of the data
 * set) is stored here.
 * <p/>
 * <p/>
 * <p>Java class for FileDescriptionType complex type.
 * <p/>
 * <p>The following schema fragment specifies the expected content contained within this class.
 * <p/>
 * <pre>
 * &lt;complexType name="FileDescriptionType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="fileContent" type="{http://psi.hupo.org/schema_revision/mzML_1.0.0}ParamGroupType"/>
 *         &lt;element name="sourceFileList" type="{http://psi.hupo.org/schema_revision/mzML_1.0.0}SourceFileListType" minOccurs="0"/>
 *         &lt;element name="contact" type="{http://psi.hupo.org/schema_revision/mzML_1.0.0}ParamGroupType" maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FileDescriptionType", propOrder = {
        "fileContent",
        "sourceFileList",
        "contact"
        })
public class FileDescription
        implements Serializable, MzMLObject {

    private final static long serialVersionUID = 100L;
    @XmlElement(required = true)
    protected ParamGroup fileContent;
    protected SourceFileList sourceFileList;
    protected List<ParamGroup> contact;

    /**
     * Gets the value of the fileContent property.
     *
     * @return possible object is
     *         {@link ParamGroup }
     */
    public ParamGroup getFileContent() {
        return fileContent;
    }

    /**
     * Sets the value of the fileContent property.
     *
     * @param value allowed object is
     *              {@link ParamGroup }
     */
    public void setFileContent(ParamGroup value) {
        this.fileContent = value;
    }

    /**
     * Gets the value of the sourceFileList property.
     *
     * @return possible object is
     *         {@link SourceFileList }
     */
    public SourceFileList getSourceFileList() {
        return sourceFileList;
    }

    /**
     * Sets the value of the sourceFileList property.
     *
     * @param value allowed object is
     *              {@link SourceFileList }
     */
    public void setSourceFileList(SourceFileList value) {
        this.sourceFileList = value;
    }

    /**
     * Gets the value of the contact property.
     * <p/>
     * <p/>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the contact property.
     * <p/>
     * <p/>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getContact().add(newItem);
     * </pre>
     * <p/>
     * <p/>
     * <p/>
     * Objects of the following type(s) are allowed in the list
     * {@link ParamGroup }
     */
    public List<ParamGroup> getContact() {
        if (contact == null) {
            contact = new ArrayList<ParamGroup>();
        }
        return this.contact;
    }

    private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
        try {
            //it is essential to be able to distinguish between the ParamGroup
            //types because there are 2 distinct collections that need to map
            //to two distint members. We can't round-trip correctly if we
            //don't store them to two different tables

            //update fileContent param group
            ParamGroupUpdater.updateParamGroupSubclasses(this.fileContent, FileDescriptionCVParam.class, FileDescriptionUserParam.class);

            //update contact list
            if (this.contact != null && !this.contact.isEmpty()) {
                List<ParamGroup> tmpContact = new ArrayList<ParamGroup>();
                for (ParamGroup aContact : contact) {
                    ParamGroupUpdater.updateParamGroupSubclasses(aContact, ContactCVParam.class, ContactUserParam.class);
                    tmpContact.add(aContact);
                }
                contact.clear();
                contact.addAll(tmpContact);
            }

        } catch (InstantiationException e) {
            throw new RuntimeException(this.getClass().getName() + ".afterUnmarshall: " + e.getMessage());
        } catch (IllegalAccessException e) {
            throw new RuntimeException(this.getClass().getName() + ".afterUnmarshall: " + e.getMessage());
        }
    }


}

